package com.bestcem.xm.qdes.config;

import com.alibaba.fastjson.JSON;
import com.github.benmanes.caffeine.cache.Cache;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @ClassName: RunnerLoadData
 * @Description:
 * @Author: chenglong.yue
 * @Date: 2022/10/13 17:26
 */
@Slf4j
@Component
public class RunnerLoadData implements CommandLineRunner {

    public RunnerLoadData(@NonNull Cache<String, Object> xmQdesCache, @NonNull StaticFile staticFile) {
        this.xmQdesCache = xmQdesCache;
        this.staticFile = staticFile;
    }

    @Qualifier("xmQdesCache")
    private final Cache<String, Object> xmQdesCache;

    private final StaticFile staticFile;

    @Override
    public void run(String... args) {
        initBaseSurveyFile();
    }

    private void initBaseSurveyFile() {
        log.info("加载survey js css配置:" + JSON.toJSONString(staticFile));
        xmQdesCache.put("base_css", staticFile.getBaseCss());
        xmQdesCache.put("base_rem_css", staticFile.getBaseRemCss());
        xmQdesCache.put("base_js", staticFile.getBaseJs());
        xmQdesCache.put("base_rem_js", staticFile.getBaseRemJs());
    }
}
